package com.sxt.atm;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class AtmView extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPasswordField passField;
	private JTextField userField;
	private AtmView atmview;

	/**
	 * Launch the application
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AtmView frame = new AtmView();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame
	 */
	public AtmView() {
		super();
		atmview = this;
		setTitle("ATM登录");
		getContentPane().setLayout(null);
		setBounds(100, 100, 337, 283);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);

		final JLabel title = new JLabel();
		title.setFont(new Font("", Font.PLAIN, 16));
		title.setText("欢迎使用ATM自助服务系统");
		title.setBounds(60, 20, 200, 39);
		getContentPane().add(title);

		final JLabel userName = new JLabel();
		userName.setText("用户名：");
		userName.setBounds(35, 80, 52, 28);
		getContentPane().add(userName);

		final JLabel passWd = new JLabel();
		passWd.setText("密     码：");
		passWd.setBounds(35, 129, 54, 28);
		getContentPane().add(passWd);

		userField = new JTextField();
		userField.setBounds(100, 80, 185, 28);
		getContentPane().add(userField);

		passField = new JPasswordField();
		passField.addKeyListener(new KeyAdapter() {
			public void keyPressed(final KeyEvent e) {
				if (e.getKeyChar() == KeyEvent.VK_ENTER) {
					if (userField.getText().equals("admin")
							&& new String(passField.getPassword()).equals("666666")) {
						atmview.setVisible(false);
						new LoginSuccess().setVisible(true);
					}
				}
			}
		});
		passField.setBounds(100, 129, 185, 28);
		getContentPane().add(passField);

		final JButton login = new JButton();
		login.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
			}
		});
		login.addMouseListener(new MouseAdapter() {
			public void mousePressed(final MouseEvent e) {
				if (userField.getText().equals("admin")
						&& new String(passField.getPassword()).equals("666666")) {
					atmview.setVisible(false);
					new LoginSuccess().setVisible(true);
				}
			}
		});
		login.setText("登录");
		login.setBounds(56, 193, 82, 28);
		getContentPane().add(login);

		final JButton reset = new JButton();
		reset.addMouseListener(new MouseAdapter() {
			public void mousePressed(final MouseEvent e) {
				userField.setText("");
				passField.setText("");
			}
		});
		reset.setText("重置");
		reset.setBounds(180, 193, 82, 28);
		getContentPane().add(reset);
		//
	}

}
